package org.fyp.synchrona.core.impl;

import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.fyp.synchrona.core.info.impl.AttributeSets;
import org.fyp.synchrona.core.info.impl.CommonDataObject;
import org.fyp.synchrona.core.info.impl.ICommonDataObject;
import org.fyp.synchrona.util.ITask;

public class AttributeComparator extends AttributeSets{
	
	private static AttributeComparator comparator= null;
	
	ICommonDataObject cdo ;
	
	private AttributeComparator(){
		
	}
	
	public static synchronized AttributeComparator getAttributeComparatorObject(){
		
		if(comparator == null){
			comparator = new AttributeComparator();
			return comparator;
		}else{
			return comparator;
		}
		
	}
	
	public ICommonDataObject createCommonObject(List l){
		cdo = new CommonDataObject();
		Iterator listIterator = l.iterator();
		while(listIterator.hasNext()) {

		   ITask element = (ITask) listIterator.next(); 
		   // System.out.print(element.getAttributeName()+"\n");
		   Set aSet = EnumSet.allOf(SEX.class);
		   Iterator aSetIterator = aSet.iterator();
		   do{
				   SEX sex = (SEX) aSetIterator.next();
				   //System.out.println("set item :: "+sex);
				   String attributeName = element.getAttributeName();
				   String setItem = ""+sex;
				   if(attributeName.equals(setItem)){
					   System.out.println("**************************************sex match");
					   cdo.setSEX(element.getAttributeValue());
				   }
		   }while(aSetIterator.hasNext());
		   
		    
		   Set BIRTHDAYSet = EnumSet.allOf(BIRTH_DAY.class);
		   Iterator  BIRTHDAYSetIterator =  BIRTHDAYSet.iterator();
		   do{
			   BIRTH_DAY bday = (BIRTH_DAY) BIRTHDAYSetIterator.next();
			   //System.out.println("set item :: "+bday);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+bday;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************Birthday match");
				   cdo.setBIRTH_DAY(element.getAttributeValue());
				   
			   }
		   }while (BIRTHDAYSetIterator.hasNext());
		   
		   
		   Set BIRTHMONTHSet = EnumSet.allOf(BIRTH_MONTH.class);
		   Iterator  BIRTHMONTHSetIterator =  BIRTHMONTHSet.iterator();
		   do{
			   BIRTH_MONTH bmonth = (BIRTH_MONTH) BIRTHMONTHSetIterator.next();
			   //System.out.println("set item :: "+bmonth);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+bmonth;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************Birthday month match");
				   cdo.setBIRTH_MONTH(element.getAttributeValue());
				   
			   }
		   }while (BIRTHMONTHSetIterator.hasNext());
		   
		   
		   Set BIRTHYEARSet = EnumSet.allOf(BIRTH_YEAR.class);
		   Iterator  BIRTHYEARSetIterator =  BIRTHYEARSet.iterator();
		   do{
			   BIRTH_YEAR byear = (BIRTH_YEAR) BIRTHYEARSetIterator.next();
			   //System.out.println("set item :: "+byear);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+byear;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************Birthday yar match");
				   cdo.setBIRTH_YEAR(element.getAttributeValue());
				   
			   }
		   }while (BIRTHYEARSetIterator.hasNext());
		   
		   
		   Set CITYSet = EnumSet.allOf(CITY.class);
		   Iterator  CITYSetIterator =  CITYSet.iterator();
		   do{
			   CITY city = (CITY) CITYSetIterator.next();
			   //System.out.println("set item :: "+city);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+city;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************city match");
				   cdo.setCITY(element.getAttributeValue());				   
			   }
		   }while (CITYSetIterator.hasNext());
		   
		   Set countrySet = EnumSet.allOf(COUNTRY.class);
		   Iterator countrySetIterator = countrySet.iterator();
		  do{
			   COUNTRY country = (COUNTRY) countrySetIterator.next();
			   //System.out.println("set item :: +++++++++++++++++++++++++++++++++++++"+country);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+country;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************currenty match");
				   cdo.setCOUNTRY(element.getAttributeValue());
			   }
		   } while(countrySetIterator.hasNext());
		  
		  
		   Set countrycitySet = EnumSet.allOf(CITY_COURNTY.class);
		   Iterator countrycitySetIterator = countrycitySet.iterator();
		   do{
			   CITY_COURNTY countrycity = (CITY_COURNTY) countrycitySetIterator.next();
			   //System.out.println("set item ::++++++++++++++++++++++++++++++ "+countrycity);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+countrycity;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************current city match");
				   cdo.setCOUNTRY_CITY(element.getAttributeValue());
			   }
		   }while(countrycitySetIterator.hasNext());
		   
		   
		   Set currentcountrycitySet = EnumSet.allOf(CURRENT_CITY_COUNTRY.class);
		   Iterator currentcountrycitySetIterator = currentcountrycitySet.iterator();
		   do{
			   CURRENT_CITY_COUNTRY currentcountrycity = (CURRENT_CITY_COUNTRY) currentcountrycitySetIterator.next();
			   //System.out.println("set item :: **********************************"+currentcountrycity);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+currentcountrycity;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************currentcountry city match");
				   cdo.setCURRENT_COUNTRY_CITY(element.getAttributeValue());
			   }
		   }while(currentcountrycitySetIterator.hasNext());
		   
		   
		   Set bioSet = EnumSet.allOf(BIO.class);
		   Iterator bioSetIterator = bioSet.iterator();
		   do{
			   BIO bio = (BIO) bioSetIterator.next();
			   //System.out.println("set item :: "+bio);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+bio;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************bio match");
				   cdo.setBIO(element.getAttributeValue());
			   }
		   }while(bioSetIterator.hasNext());
		   
		   
		   Set fullnameSet = EnumSet.allOf(FULL_NAME.class);
		   Iterator fullnameSetIterator = fullnameSet.iterator();
		   do{
			   FULL_NAME fullname = (FULL_NAME) fullnameSetIterator.next();
			   //System.out.println("set item :: "+fullname);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+fullname;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************full name match");
				   cdo.setFULL_NAME(element.getAttributeValue());
			   }
		   }while(fullnameSetIterator.hasNext());
		   
		   
		   Set addressSet = EnumSet.allOf(ADDRESS.class);
		   Iterator addressSetIterator = addressSet.iterator();
		   do{
			   ADDRESS address = (ADDRESS) addressSetIterator.next();
			   //System.out.println("set item :: "+address);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+address;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************address match");
				   cdo.setADDRESS(element.getAttributeValue());
			   }
		   }while(addressSetIterator.hasNext());
		   
		   
		   Set websiteSet = EnumSet.allOf(WEBSITE.class);
		   Iterator websiteSetIterator = websiteSet.iterator();
		   do{
			   WEBSITE website = (WEBSITE) websiteSetIterator.next();
			   //System.out.println("set item :: "+website);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+website;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************website match");
				   cdo.setWEBSITE(element.getAttributeValue());
				   
			   }
		   }while(websiteSetIterator.hasNext());
		   
		   
		   Set mobileSet = EnumSet.allOf(MOBILE.class);
		   Iterator mobileSetIterator = mobileSet.iterator();
		   do{
			   MOBILE mobile = (MOBILE) mobileSetIterator.next();
			   //System.out.println("set item :: "+mobile);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+mobile;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************moblie match");
				   cdo.setMOBLIE(element.getAttributeValue());
			   }
		   }while(mobileSetIterator.hasNext());
		   
		   
		   Set homephoneSet = EnumSet.allOf(HOME_PHONE.class);
		   Iterator homephoneSetIterator = homephoneSet.iterator();
		   do{
			   HOME_PHONE homephone = (HOME_PHONE) homephoneSetIterator.next();
			   //System.out.println("set item :: "+homephone);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+homephone;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************homephone match");
				   cdo.setHOME_PHONE(element.getAttributeValue());
			   }
		   }while(homephoneSetIterator.hasNext());
		   
		   
		   Set firstnameSet = EnumSet.allOf(FIRST_NAME.class);
		   Iterator firstnameSetIterator = firstnameSet.iterator();
		   do{
			   FIRST_NAME firstname = (FIRST_NAME) firstnameSetIterator.next();
			   //System.out.println("set item :: "+firstname);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+firstname;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************firstname match");
				   cdo.setFIRST_NAME(element.getAttributeValue());
			   }
		   }while(firstnameSetIterator.hasNext());
		   
		   
		   Set lastnameSet = EnumSet.allOf(LAST_NAME.class);
		   Iterator lastnameSetIterator = lastnameSet.iterator();
		   do{
			   LAST_NAME lastname = (LAST_NAME) lastnameSetIterator.next();
			   //System.out.println("set item :: "+lastname);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+lastname;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************last name match");
				   cdo.setLAST_NAME(element.getAttributeValue());
			   }
		   }while(lastnameSetIterator.hasNext());
		   
		   
		   Set usernameSet = EnumSet.allOf(USERNAME.class);
		   Iterator usernameSetIterator = usernameSet.iterator();
		   do{
			   USERNAME username = (USERNAME) usernameSetIterator.next();
			   //System.out.println("set item :: "+username);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+username;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************username match");
				   cdo.setUSER_NAME(element.getAttributeValue());
			   }
		   }while(usernameSetIterator.hasNext());
		   
		   
		   Set photoheightSet = EnumSet.allOf(PHOTO_HEIGHT.class);
		   Iterator photoheightSetIterator = photoheightSet.iterator();
		   do{
			   PHOTO_HEIGHT photoheight = (PHOTO_HEIGHT) photoheightSetIterator.next();
			   //System.out.println("set item :: "+photoheight);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+photoheight;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************photo height match");
				   cdo.setPHOTO_HEIGHT(element.getAttributeValue());
			   }
		   }while(photoheightSetIterator.hasNext());
		   
		   
		   Set photourlSet = EnumSet.allOf(PHOTO_URL.class);
		   Iterator photourlSetIterator = photourlSet.iterator();
		   do{
			   PHOTO_URL photourl = (PHOTO_URL) photourlSetIterator.next();
			   //System.out.println("set item :: "+photourl);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+photourl;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************photo url match");
				   cdo.setPHOTO_URL(element.getAttributeValue());
			   }
		   }while(photourlSetIterator.hasNext());
		   
		   
		   Set photowidthSet = EnumSet.allOf(PHOTO_WIDTH.class);
		   Iterator photowidthSetIterator = photowidthSet.iterator();
		   do{
			   PHOTO_WIDTH photowidth = (PHOTO_WIDTH) photowidthSetIterator.next();
			   //System.out.println("set item :: "+photowidth);
			   String attributeName = element.getAttributeName();
			   String setItem = ""+photowidth;
			   if(attributeName.equals(""+setItem)){
				   System.out.println("**************************************photo widht match");
				   cdo.setPHOTO_WIDTH(element.getAttributeValue());
			   }
		   }while(photowidthSetIterator.hasNext());
		   
		   
		  /* Set USERNAMESet = EnumSet.allOf(USERNAME.class);  
		   Iterator USERNAMEIterator = USERNAMESet.iterator();  
		   do {  
		        USERNAME uname = (USERNAME) USERNAMEIterator.next();  
		        //System.out.println("set item ::"+uname);
		        String attributeName = element.getAttributeName();
		        String setItem = ""+uname;
		        //System.out.println("attribute value ::"+element.getAttributeName());
		        if(attributeName.equals(""+setItem)){
		        	System.out.println("***************************************** username match");
		        	cdo.setUSER_NAME(element.getAttributeValue());
		        }		      
		   } while (USERNAMEIterator.hasNext());*/
		   
		   Set STATUSSet = EnumSet.allOf(STATUS.class);
		   Iterator STATUSIterator = STATUSSet.iterator();
		   do {  
		        STATUS status = (STATUS) STATUSIterator.next();  
		        //System.out.println("set item ::"+uname);
		        String attributeName = element.getAttributeName();
		        String setItem = ""+status;
		        //System.out.println("attribute value ::"+element.getAttributeName());
		        if(attributeName.equals(""+setItem)){
		        	System.out.println("**************************************status match");
		        	cdo.setSTATUS(element.getAttributeValue());
		        }		      
		   } while (STATUSIterator.hasNext());
		   
		   Set EMAILSet = EnumSet.allOf(EMAIL.class);
		   Iterator EMAILIterator = EMAILSet.iterator();
		   do {  
		        EMAIL email = (EMAIL) EMAILIterator.next();  
		        //System.out.println("set item ::"+uname);
		        String attributeName = element.getAttributeName();
		        String setItem = ""+email;
		        //System.out.println("attribute value ::"+element.getAttributeName());
		        if(attributeName.equals(""+setItem)){
		        	System.out.println("**************************************email match");
		        	cdo.setEMAIL(element.getAttributeValue());
		        }		      
		   } while (EMAILIterator.hasNext());
		   
		   Set INTERESTSet = EnumSet.allOf(INTEREST.class);
		   Iterator INTERESTterator = INTERESTSet.iterator();
		   do {  
			   INTEREST interest = (INTEREST) INTERESTterator.next();  
		        //System.out.println("set item ::"+uname);
		        String attributeName = element.getAttributeName();
		        String setItem = ""+interest;
		        //System.out.println("attribute value ::"+element.getAttributeName());
		        if(attributeName.equals(""+setItem)){
		        	System.out.println("**************************************interest match");
		        	cdo.setINTERESTS(element.getAttributeValue());
		        }		      
		   } while (INTERESTterator.hasNext());
		    	    
		} 
		
		return cdo;
	}

}
